#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
#include <QDebug>
#include <QResizeEvent>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //创建QLabel
    _label = new QLabel(this);
    //设置Qlabel背景图
    _label->setPixmap(QPixmap(":/funny.png"));
    //设置Qlabel的尺寸为Widget的尺寸
    QRect rect = geometry();
    _label->setGeometry(0, 0, rect.width(), rect.height());
    //设置label的内容自动拉伸,填充整个label的尺寸
    _label->setScaledContents(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::resizeEvent(QResizeEvent *event)
{
    qDebug() << event->size();
    _label->setGeometry(0, 0, event->size().width(), event->size().height());
}

